package com.crdeng.system.controller;


import com.crdeng.response.Result;
import com.crdeng.system.service.AliOssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Api(value = "Oss模块", tags = "Oss模块")
@RestController
@RequestMapping("/oss")
public class AliyunOssController {
    @Autowired
    private AliOssService aliOssService;


    @ApiOperation(value = "文件上传", notes = "上传文件")
    @PostMapping("/uploadFile")
    public Result uploadAvetar(MultipartFile file) {
        String url = aliOssService.upload(file);

        System.out.println("文件上传" + url);

        if (url != null) {
            return Result.ok().data("url", url);

        } else {
            return Result.error();
        }
    }

    @ApiOperation(value = "删除文件",notes = "删除OSS的文件")
    @DeleteMapping("/deleteFile")
    public Result delete(String fileName){
        String[] split = fileName.split(".com/");
        System.out.println(split[1]);
        aliOssService.deleteFile(split[1]);

        return Result.ok();
    }



}
